package com.jrzh.mvc.convert.sys;

import com.jrzh.common.exception.ProjectException;
import com.jrzh.common.utils.ReflectUtils;
import com.jrzh.framework.base.convert.BaseConvertI;
import com.jrzh.mvc.model.sys.LoginLogModel;
import com.jrzh.mvc.model.sys.UserModel;
import com.jrzh.mvc.view.sys.LoginLogView;

public class LoginLogConvert implements BaseConvertI<LoginLogModel, LoginLogView> {

	@Override
	public LoginLogModel addConvert(LoginLogView view) throws ProjectException {
		LoginLogModel model = new LoginLogModel();
		ReflectUtils.copySameFieldToTarget(view, model);
		return model;
	}

	@Override
	public LoginLogModel editConvert(LoginLogView view, LoginLogModel model) throws ProjectException {
		ReflectUtils.copySameFieldToTargetFilter(view, model, new String[]{"createBy", "createTime"});
		return model;
	}

	@Override
	public LoginLogView convertToView(LoginLogModel model) throws ProjectException {
		LoginLogView view = new LoginLogView();
		ReflectUtils.copySameFieldToTarget(model, view);
		UserModel user = model.getUser();
		if(null !=user){
			view.setUserName(user.getName());
		}
		return view;
	}

}
